<template>
    <div class="page-partner-detail">
        <div v-if="service">
            <img class="page-partner-detail__banner" :src="service.partner_bg" mode="widthFix" />
        </div>
        <div class="btn-wrap">
            <div class="btn btn-mobile btn-red btn-large btn-ract btn-block" @click="onClickApply">
                {{statusText}}
            </div>
        </div>
    </div>
</template>

<script lang="ts">
import store from '@/store';
import { api } from '@/lib/api';
import { Component, Vue } from 'vue-property-decorator';
import { ROUTE_NAME } from '@/lib/constant';

@Component({
    name: 'PartnerDetail',
})
export default class PartnerDetail extends Vue {
    public satusText: any = {
        init: '等待申请结果',
        pass: '申请成功',
        fail: '申请成为城市合伙人',
    };

    /** 用户基础信息 */
    public get userBasicInfo() {
        return store.state.user.basicInfo;
    }

    /** 服务信息 */
    public get service() {
        return store.state.utils.service;
    }

    public get application() {
        return store.state.user.application;
    }

    public get statusText() {
        if (!this.application) {
            return '申请成为城市合伙人';
        } else {
            if (this.application.status === 'init') {
                return '等待申请结果';
            } else if (this.application.status === 'pass' && this.userBasicInfo.level === 2) {
                return '申请成功';
            }
        }
        return '申请成为城市合伙人';
    }

    public onClickApply() {
        if (!this.service) {
            return;
        }
        if (this.service && Number(this.service.can_apply_partner) === 0) {
            wx.showToast({
                title: '申请城市合伙人暂未开放，请咨询管理人员',
                icon: 'none',
            });
            return;
        }
        if (this.application) {
            // wx.navigateTo({
            //     url: '/pages/partner_apply_rate/main',
            // });
            api.push({
                name: ROUTE_NAME.PARTNER_APPLY_RATE,
            });
            return;
        }
        // wx.navigateTo({
        //     url: '/pages/partner_apply/main',
        // });
        api.push({
            name: ROUTE_NAME.PARTNER_APPLY,
        });
    }

    async created() {
        await store.dispatch('user/getApplication');
    }
}
</script>

<style lang="less">
@import "../../lib/style/mixins.less";

.page-partner-detail {
    padding-bottom: 44px;
    &__banner {
        width: 100%;
        vertical-align: middle;
    }
    .btn-wrap {
        box-sizing: border-box;
        position: fixed;
        left: 0;
        bottom: 0;
        width: 100%;
        .btn {
            border-radius: 0;
        }
    }
}

</style>
